<template>
  <el-dialog
    :title="params.id ? '修改学科' : '新增学科'"
    :visible.sync="showDialog"
    width="440px"
    @close="hClose"
  >
    <el-form :model="params" ref="form" label-width="80px">
      <el-form-item
        label="学科名称"
        prop="subjectName"
        :rules="[
          { required: true, message: '请选择学科名称', trigger: 'blur' },
        ]"
      >
        <el-input v-model="params.subjectName" style="width: 270px"></el-input>
      </el-form-item>
      <el-form-item label="是否显示" >
        <el-switch
          v-model="params.isFrontDisplay"
          active-color="#13ce66"
          inactive-color="#ff4949"
          active-value="1"
          inactive-value="0"
        >
        </el-switch>
      </el-form-item>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button @click="hClose">取 消</el-button>
      <el-button type="primary" @click="hConfirm">确 定</el-button>
    </span>
  </el-dialog>
</template>

<script>
import { add, update } from '@/api/hmmm/subjects'
export default {
  data () {
    return {
      showDialog: false,
      params: {
        subjectName: '',
        isFrontDisplay: ''
      }
    }
  },
  methods: {
    hClose () {
      this.$refs.form.resetFields()
      this.showDialog = false
      this.params = {}
    },
    async hConfirm () {
      console.log(this.params)
      await this.$refs.form.validate()
      this.params.id ? await update(this.params) : await add(this.params)
      this.$message.success(`${this.params.id ? '修改' : '新增'}成功`)
      this.showDialog = false
      this.$emit('updateList')
    }
  }
}
</script>

<style scoped lang='less'></style>
